package com.neuedu.api;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class MyTime {

    public static void main(String args[]){

        Date date = new Date();



        Calendar now = Calendar.getInstance();


        //获取字段
        System.out.println("年："+now.get(Calendar.YEAR));
        System.out.println("月："+now.get(Calendar.MONTH));
        System.out.println("日："+now.get(Calendar.DATE));
        System.out.println("日DAY_OF_MONTH："+now.get(Calendar.DAY_OF_MONTH));
        System.out.println("日DAY_OF_WEEK："+now.get(Calendar.DAY_OF_WEEK));
        System.out.println("日DAY_OF_YEAR："+now.get(Calendar.DAY_OF_YEAR));

        System.out.println("时："+now.get(Calendar.HOUR));  // 12小时制
        System.out.println("时："+now.get(Calendar.HOUR_OF_DAY)); // 12小时制
        System.out.println("分："+now.get(Calendar.MINUTE));
        System.out.println("秒："+now.get(Calendar.SECOND));


        //设置字段
        now.set(Calendar.HOUR,3);
        System.out.println("update->时："+now.get(Calendar.HOUR_OF_DAY));


        //compare
        Calendar now2 = Calendar.getInstance();
        System.out.println("now2.compareTo(now):\t"+now2.compareTo(now));


        System.out.println("now.before(now2)\t"+now.before(now2));
        System.out.println("now.after(now2)\t"+now.after(now2));
        String formatter = "yyyy-MM-dd HH:mm:ss";
        SimpleDateFormat sdf = new SimpleDateFormat(formatter);

        //
        System.out.println("sdf.format(now2.getTime())\t"+sdf.format(now2.getTime()));


        //时区
        String[] avTimeZoneIds = TimeZone.getAvailableIDs();
        for (String avTimeZoneId : avTimeZoneIds) {
            System.out.println("有效的时区：avTimeZoneId\t"+avTimeZoneId);
        }
        Calendar now3 = Calendar.getInstance(TimeZone.getTimeZone("Etc/GMT-11"));
//
        System.out.println("now3:"+sdf.format(now3.getTime()));


    }
}
